<template>
    <div
        class="automaticstagset-contnair"
        v-loading="isLoading"
        element-loading-background="rgba(250, 250, 250, 0.7)"
    >
        <!-- 账单自动分期设置 -->
        <!-- <el-card shadow="never">
      <div slot="headerss" class="clearfix">
        <span>自动分期设置</span>
        <el-button style="float: right; padding: 3px 20px;" type="text" @click="showTrial=false">关 闭</el-button>
        </div>-->
        <cardComponent pageTitle="自动分期设置">
            <template slot="cardBody">
                <el-form ref="form" :model="sizeForm" label-width="170px" size="small">
                    <el-row>
                        <el-col :span="8">
                            <el-form-item label="账户类别:" class="text_fl">
                                <el-select
                                    v-model="sizeForm.accttype"
                                    placeholder="请选择账户类别"
                                    clearable
                                    @change="changeCardList"
                                >
                                    <el-option
                                        v-for="item in AccountionTYPE_INFO"
                                        :label="item.label"
                                        :value="item.code"
                                        :key="item.label"
                                    ></el-option>
                                </el-select>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item label="卡号:" class="text_fl">
                                <el-select
                                    v-model="sizeForm.CARDNBR"
                                    placeholder="请选择卡号"
                                    clearable
                                    :disabled="true"
                                >
                                    <el-option
                                        v-for="item in cardList"
                                        :label="item.CARDNBR"
                                        :value="item.CARDNBR"
                                        :key="item.CARDNBR"
                                    ></el-option>
                                </el-select>
                            </el-form-item>
                        </el-col>
                    </el-row>
                </el-form>
                <div style="margin-left:10px;">
                    <!-- <el-divider content-position="center"></el-divider> -->
                    <el-table
                        :data="acctPlanData"
                        border
                        stripe
                        class="heard-bg business_table"
                        style="width: 99%;"
                        size="small"
                    >
                        <el-table-column label="账户级自动分期计划">
                            <el-table-column prop="CPNOACCT" label="计划编号"></el-table-column>
                            <el-table-column prop="CPNAME" label="产品名称"></el-table-column>
                            <el-table-column prop="MINAMTACCT" label="起分金额" width="150">
                                <template slot-scope="scope">
                                    <!-- <el-input class="payAcount" v-model="scope.row.MINAMTACCT"></el-input> -->
                                    <el-select
                                        v-model="scope.row.MINAMTACCT"
                                        placeholder="请选择起分金额"
                                        :disabled="scope.row.CPNOACCT!==5048||scope.row.IFFLG"
                                    >
                                        <el-option
                                            v-for="item in autominamt"
                                            :label="item.code"
                                            :value="item.code"
                                            :key="item.code"
                                        ></el-option>
                                    </el-select>

                                    <!-- <el-button
                                        type="primary"
                                        size="small"
                                        @click="updateacct(scope.row)"
                                    >修改</el-button>-->
                                </template>
                            </el-table-column>
                            <el-table-column prop="NBRMTHACCT" label="默认期数" width="150">
                                <template slot-scope="scope">
                                    <!-- <el-input class="payAcount" v-model="scope.row.NBRMTHACCT"></el-input> -->
                                    <el-select
                                        v-model="scope.row.NBRMTHACCT"
                                        placeholder="请选择期数"
                                        :disabled="scope.row.IFFLG"
                                    >
                                        <el-option
                                            v-for="item in scope.row.NBRLIST"
                                            :label="item"
                                            :value="item"
                                            :key="item"
                                        ></el-option>
                                    </el-select>
                                    <!-- <el-button
                                        type="primary"
                                        size="small"
                                        @click="updateacct(scope.row)"
                                    >修改</el-button>-->
                                </template>
                            </el-table-column>
                            <el-table-column prop="PAYTYPEACCT" label="本金分摊方式"></el-table-column>
                            <el-table-column prop="FEETYPEACCT" label="手续费分摊方式" min-width="150"></el-table-column>
                            <el-table-column prop="FEECODE" label="手续费率">
                                <template
                                    slot-scope="scope"
                                >{{scope.row.NBRMTHACCT|getfee(scope.row.NBRLIST,scope.row.FEELIST)}}</template>
                            </el-table-column>
                            <el-table-column prop="CARDEND" label="卡号后四位">
                                >
                                <template slot-scope="scope">{{scope.row.CARDEND|getcardend}}</template>
                            </el-table-column>
                            <el-table-column label="操作">
                                <template slot-scope="scope">
                                    <el-button
                                        type="primary"
                                        size="small"
                                        @click="updateacct(scope.row)"
                                        :disabled="scope.row.IFFLG"
                                    >修 改</el-button>
                                </template>
                            </el-table-column>
                        </el-table-column>
                    </el-table>

                    <el-divider content-position="center"></el-divider>
                    <el-table
                        :data="cardPlanData"
                        border
                        stripe
                        class="heard-bg business_table"
                        style="width: 99%;"
                        size="small"
                    >
                        <el-table-column label="卡片级自动分期计划">
                            <el-table-column prop="CPNO" label="计划编号"></el-table-column>
                            <el-table-column prop="CPNAME" label="产品名称"></el-table-column>
                            <el-table-column prop="MINAMT" label="起分金额" width="150">
                                <template slot-scope="scope">
                                    <el-select
                                        v-model="scope.row.MINAUTAMT"
                                        placeholder="请选择起分金额"
                                        :disabled="scope.row.CPNO!==5048||scope.row.IFFLG"
                                    >
                                        <el-option
                                            v-for="item in autominamt"
                                            :label="item.code"
                                            :value="item.code"
                                            :key="item.code"
                                        ></el-option>
                                    </el-select>
                                </template>
                            </el-table-column>
                            <el-table-column prop="NBRMTH" label="默认期数" width="150">
                                <template slot-scope="scope">
                                    <el-select
                                        v-model="scope.row.NBRMTH"
                                        placeholder="请选择期数"
                                        :disabled="scope.row.IFFLG"
                                    >
                                        <el-option
                                            v-for="item in scope.row.NBRLIST"
                                            :label="item"
                                            :value="item"
                                            :key="item"
                                        ></el-option>
                                    </el-select>
                                </template>
                            </el-table-column>
                            <el-table-column prop="PAYTYPE" label="本金分摊方式"></el-table-column>
                            <el-table-column prop="FEETYPE" label="手续费分摊方式" width="150"></el-table-column>
                            <el-table-column prop="FEECODE" label="手续费率">
                                <template
                                    slot-scope="scope"
                                >{{scope.row.NBRMTH | getfee(scope.row.NBRLIST,scope.row.FEELIST)}}</template>
                            </el-table-column>
                            <el-table-column prop="CARDEND" label="卡号后四位">
                                >
                                <template slot-scope="scope">{{scope.row.CARDEND|getcardend}}</template>
                            </el-table-column>
                            <el-table-column label="操作">
                                <template slot-scope="scope">
                                    <el-button
                                        type="primary"
                                        size="small"
                                        @click="updatecard(scope.row)"
                                        :disabled="scope.row.IFFLG"
                                    >修 改</el-button>
                                </template>
                            </el-table-column>
                        </el-table-column>
                    </el-table>
                </div>
                <!-- 话术 -->
                <div class="hstable_wrap" v-if="speechList.length!=0">
                    <el-table
                        :data="speechList"
                        border
                        stripe
                        header-row-class-name="headerRow"
                        ref="showListTable"
                        class="heard-bg business_table hstable"
                        @selection-change="handleSelectionChange"
                    >
                        <el-table-column type="selection" label=" " min-width="55"></el-table-column>
                        <el-table-column label="业务话术">
                            <template slot-scope="scope">{{scope.row.content}}</template>
                        </el-table-column>
                    </el-table>
                </div>

                <el-dialog
                    v-drag
                    title="自动分期计划修改"
                    :visible.sync="centerDialogVisibleclose1"
                    width="500px"
                    :append-to-body="true"
                    top="30vh"
                    :close-on-click-modal="false"
                    center
                >
                    <p>
                        修改类型：
                        <span>{{this.confimData.UPDTYPE==='0'?'账户级自动分期计划':'卡片级自动分期计划'}}</span>
                    </p>
                    <p v-if="this.confimData.CARDNO!==''">
                        卡号：
                        <span>{{this.confimData.CARDNO}}</span>
                    </p>
                    <p>
                        计划编号：
                        <span>{{this.confimData.PLAINNO}}</span>
                    </p>
                    <p>
                        起分金额：
                        <span>{{this.confimData.UPDTYPE==='1'?this.confimData.MINAUTAMT:this.confimData.MINMPAMT}}</span>
                    </p>
                    <p>
                        期数：
                        <span>{{this.confimData.NBRMTH}}</span>
                    </p>
                    <p class="text_center padding_top15">
                        <span style="color:#3a8ee6; ">您确认要修改自动分期计划信息吗？</span>
                    </p>
                    <span slot="footer" class="dialog-footer">
                        <el-button
                            size="small"
                            icon="el-icon-circle-close"
                            @click="centerDialogVisibleclose1 = false"
                        >取 消</el-button>
                        <el-button
                            type="primary"
                            size="small"
                            @click="submitForm"
                            icon="el-icon-circle-check"
                        >确定</el-button>
                    </span>
                </el-dialog>
                <!-- </el-card> -->
                <div class="text_center margin_top20">
                    <el-button type="primary" size="small" @click="handleClickbtn">修改记录查询</el-button>
                </div>
            </template>
        </cardComponent>
    </div>
</template>

<script>
import { mapState } from 'vuex';
import cardComponent from '@/components/cardComponent/cardComponent.vue';
import { INSTALMENT_QS1, INSTALMENT_QS2 } from 'utils/Contants';
import {
    getInstalmentList,
    getDictSelectList,
    getDictMappingValue, getBusinessMenuId
} from '@/utils/Common';
import { get_4xxx, get_3xxx } from '@/apis/getAPIClass';
import { setNumber, ChangePage } from '@/utils/Object';

export default {
    data() {
        return {
            sizeForm: {
                // 3052
                CATEGORY: '',
                CARDNBR: '',
                CPNOACCT: '',
                NBRMTHACCT: '',
                MINAMTACCT: '',
                CPNO2: '',
                NBRMTH2: '003',
                CPNO: '',
                NBRMTH: '',
                MINAMT: '',
                accttype: '',
                cardno: '',
            },

            cardList: [],
            acctPlanData: [],//账户级自动分期计划
            cardPlanData: [],//卡片级自动分期计划
            selectList: [],
            fqList: INSTALMENT_QS1,
            showTrial: false,
            showEdit: false,
            isLoading: false,
            is3: true,
            qfjeDisableFlag: true,
            qfjeList: [
                {
                    label: '500',
                    value: '500',
                },
                {
                    label: '1000',
                    value: '1000',
                },
                {
                    label: '3000',
                    value: '3000',
                },
            ],
            SEVOPT: '',
            IccMpprm: '',//分期计划数据
            acctMinList: [],
            autominamt: [],//自动分期起分金额
            speechList: [],//话术列表
            selectedList: [],
            MenuId: '',
            confimData: {
                UPDTYPE: '',
                CARDNO: '',
                PLAINNO: '',
                NBRMTH: '',
                MINMPAMT: '',
                MAXMPAMT: '',
                MINAUTAMT: '',
            },
            centerDialogVisibleclose1: false,
        };
    },
    name: 'automaticstagset',
    components: {
        cardComponent,
    },
    filters: {
        getcardend: (value) => {

            return value.substring(12, 16);
        },
        getfee: (value, nbrlist, feelist) => {
            let text = '';
            if (value + '' === '0') {
                return '';
            }
            for (let i = 0; i < nbrlist.length; i++) {
                if (nbrlist[i] + '' === value + '') {
                    text = feelist[i];
                    break;
                }
            }
            //console.log("期数：" + value + ",费率：" + text);
            return parseFloat(text * 100).toFixed(2) + '%';
        },
    },
    // async created() {
    //     //this.fqList = await getDictSelectList('AUTO_INSTALMENT', this);

    //     this.onLoadAutoOBJ();
    // },

    async mounted() {
        this.MenuId = this.$route.params.id || '';
        await this.getInitData();

        //this.sizeForm.CATEGORY = await getDictMappingValue('CATE', this.cardInfo_3004.CATEGORY, this) || this.cardInfo_3004.CATEGORY;
        this.autominamt = await getDictSelectList('AUTOMINAMT', this);

        this.init();
        this.changeCardList(this.cardInfo_3004.CATEGORY + '');
        await this.getspeechList();
    },
    computed: mapState({
        defaultParams: state => state.common.defaultParams, // 接口默认参数
        cardInfo_3004: state => state.common.cardInfo_3004,
        cardList_3601: state => state.common.cardList_3601,
        AccountionTYPE_INFO: state => state.common.AccountionTYPE_INFO, //账户类别列表
        pinFlag: state => state.common.pinFlag, // 是否密码检查标志
        isCurrentMenuInfo: state => state.menu.isCurrentMenuInfo,
        businessMenu: state => state.menu.businessMenu,
    }),
    methods: {
        init() {
            this.MenuId = this.$route.params.id || '';
            console.log("默认账户类别：" + this.cardInfo_3004.CATEGORY);
            console.log("默认账户：" + this.cardInfo_3004.CARDNO);
            this.sizeForm.accttype = this.cardInfo_3004.CATEGORY + '';
            this.sizeForm.CARDNBR = this.cardInfo_3004.CARDNO;


        },
        changeCardList(val) {
            console.log("当前账户类型：" + val);
            let hasDefault = false; //是否包含默认卡
            this.cardList = [];
            this.cardList_3601.forEach((item) => {
                if (item.CATEGORY + '' === val) {
                    this.cardList.push(item);
                    if (item.CARDNBR === this.cardInfo_3004.CARDNO) {
                        hasDefault = true;
                    }
                }
            });

            //包含默认卡，卡号显示默认卡，不包含，显示cardList里第一张卡号
            if (hasDefault) {
                this.sizeForm.CARDNBR = this.cardInfo_3004.CARDNO;
            } else {
                this.sizeForm.CARDNBR = this.cardList[0].CARDNBR;
            }

            this.onLoadAutoOBJ3();
        },
        //根据菜单id查询话术列表
        async getspeechList() {
            console.log("this.isCurrentMenuInfo.id", this.isCurrentMenuInfo.id);
            var checkParam = {
                'id': this.MenuId || this.isCurrentMenuInfo.id,
            };
            this.$post.busiMenu.getlistByMenuId(checkParam).then((res) => {
                console.log("话术查询结果：", res);
                if (res.status === 200) { // http通讯成功
                    if (res.data.status == 0) { // 业务请求成功
                        this.speechList = res.data.content;
                    }
                }
            });
        },
        handleSelectionChange(val) {
            this.selectedList = val;
        },
        // 获取分期计划对应的数据
        async getInitData() {
            let params = {
                pageNum: 1,
                pageSize: 10,
                itemNo: '',
            };
            await this.$post.MpprmPlan.findAllIccMpprm(params).then((res) => {
                if (res.data.success) {
                    this.IccMpprm = res.data.content;
                    console.log('分期计划__IccMpprm', this.IccMpprm);
                } else {
                    this.$alert('分期计划数据请求失败', '提示', {
                        customClass: 'warning', type: 'warning',
                    });
                }

            });
        },


        async onLoadAutoOBJ3() {
            this.acctPlanData = [];
            this.cardPlanData = [];
            this.cardList.forEach(async (item) => {
                if (item.MAFLAG + '' === '1') {
                    let cardPlan = {
                        CPNO: '',
                        CPNAME: '',
                        NBRMTH: '',
                        MINAUTAMT: '',
                        MINAMT: '',
                        MAXAMT: '',
                        PAYTYPE: '',
                        FEETYPE: '',
                        FEECODE: '',
                        CARDEND: '',
                        IFFLG: true
                    };
                    let acctPlan = {
                        CPNOACCT: '',
                        CPNAME: '',
                        NBRMTHACCT: '',
                        NBRLIST: '',
                        MINAMTACCT: '',
                        MAXAMTACCT: '',
                        PAYTYPEACCT: '',
                        FEETYPEACCT: '',
                        FEECODE: '',
                        CARDEND: '',
                        IFFLG: true
                    };
                    const appBody_3014 = {
                        CARDNBR: item.CARDNBR,
                        PINFLAG: '0',
                    };
                    console.log(appBody_3014);
                    const result_3014 = await get_3xxx(
                        '3014',
                        '自动分期查询',
                        appBody_3014,
                        this,
                    );
                    console.log("result_3014", result_3014);
                    if (!result_3014) return false;

                    // result_3014.body.appBody.CPNO = '2002';
                    // result_3014.body.appBody.NBRMTH = '6';
                    // result_3014.body.appBody.MINAMT = '1000';

                    //如果自动分期计划存在，获取分期计划相关信息
                    // if (result_3014.body.appBody.CPNO != '0') {
                    console.log("result_3014.body.appBody.CPNO" + result_3014.body.appBody.CPNO + ",result_3014.body.appBody.CPNOACCT" + result_3014.body.appBody.CPNOACCT);
                    //循环分期计划列表
                    if (result_3014.body.appBody.CPNO != '0') {
                        for (let i = 0; i < this.IccMpprm.length; i++) {
                            let item1 = this.IccMpprm[i];
                            if (result_3014.body.appBody.CPNO + '' === item1.itemNo + '') {
                                let NBRLIST = item1.nbrMths.split(',');//获取当前分期的期数列表
                                let feetype = item1.paytype.split(',')[0];//获取手续费分摊方式
                                let paytype = item1.priType.split(',')[0];   //获取本金分摊方式

                                let feelist = item1.appFeeratio.split(',');//获取费率列表
                                let feecode = '';
                                NBRLIST.forEach((item2, index) => {
                                    if (item2 + '' === result_3014.body.appBody.NBRMTH + '') {
                                        feecode = feelist[index];
                                    }
                                });
                                console.log("feecode:", feecode);
                                cardPlan = {
                                    CPNO: result_3014.body.appBody.CPNO,
                                    CPNAME: item1.itemCm,
                                    NBRMTH: result_3014.body.appBody.NBRMTH,
                                    NBRLIST: NBRLIST,
                                    FEELIST: feelist,
                                    MINAUTAMT: result_3014.body.appBody.MINAUTAMT,
                                    MINAMT: result_3014.body.appBody.MINAMT,
                                    MAXAMT: result_3014.body.appBody.MAXAMT,
                                    PAYTYPE: paytype === '0' ? '一次性支付' : '按月支付',
                                    FEETYPE: feetype === '0' ? '一次性支付' : '按月支付',
                                    FEECODE: parseFloat(feecode * 100).toFixed(2) + '%',
                                    CARDEND: item.CARDNBR,
                                    IFFLG: false
                                };
                                console.log("cardPlan", cardPlan);
                                this.cardPlanData.push(cardPlan);
                            }
                        }
                    } else {
                        cardPlan = {
                            CPNO: '0',
                            CPNAME: '',
                            NBRMTH: '0',
                            NBRLIST: '',
                            FEELIST: '',
                            MINAUTAMT: '0',
                            MINAMT: '0',
                            MAXAMT: '0',
                            PAYTYPE: '',
                            FEETYPE: '',
                            FEECODE: '',
                            CARDEND: item.CARDNBR,
                            IFFLG: true
                        };
                        console.log("cardPlan", cardPlan);
                        this.cardPlanData.push(cardPlan);
                    }

                    if (result_3014.body.appBody.CPNOACCT != '0') {
                        console.log("this.IccMpprm", this.IccMpprm);
                        for (let i = 0; i < this.IccMpprm.length; i++) {
                            let item2 = this.IccMpprm[i];
                            if (item2.itemNo + '' === result_3014.body.appBody.CPNOACCT + '') {
                                //匹配到自动分期计划
                                console.log("iccmpitem", item2);
                                let NBRLIST = item2.nbrMths.split(',');//获取当前分期的期数列表
                                console.log("NBRLIST", NBRLIST);
                                let feetype = item2.paytype.split(',')[0];//获取手续费分摊方式
                                console.log("feetype:", feetype);
                                let paytype = item2.priType.split(',')[0];   //获取本金分摊方式
                                console.log("paytype:", paytype);

                                let feelist = item2.appFeeratio.split(',');//获取费率列表
                                //从费率列表中提取当前分期期数的费率
                                let feecode = '';
                                NBRLIST.forEach((item1, index) => {
                                    console.log("item1", item1);
                                    if (item1 + '' === result_3014.body.appBody.NBRMTHACCT + '') {
                                        feecode = feelist[index];
                                    }
                                });
                                console.log("feecode:", feecode);
                                acctPlan = {
                                    CPNOACCT: result_3014.body.appBody.CPNOACCT,
                                    CPNAME: item2.itemCm,
                                    NBRMTHACCT: result_3014.body.appBody.NBRMTHACCT,
                                    NBRLIST: NBRLIST,
                                    FEELIST: feelist,
                                    MINAMTACCT: result_3014.body.appBody.MINAMTACCT,
                                    MAXAMTACCT: result_3014.body.appBody.MAXAMTACCT,
                                    PAYTYPEACCT: paytype === '0' ? '一次性支付' : '按月支付',
                                    FEETYPEACCT: feetype === '0' ? '一次性支付' : '按月支付',
                                    FEECODE: parseFloat(feecode * 100).toFixed(2) + '%',
                                    CARDEND: item.CARDNBR,
                                    IFFLG: false
                                };
                                console.log("acctPlan", acctPlan);
                                this.acctPlanData.push(acctPlan);
                            }
                        }
                    } else {
                        acctPlan = {
                            CPNOACCT: '0',
                            CPNAME: '',
                            NBRMTHACCT: '0',
                            NBRLIST: '',
                            FEELIST: '',
                            MINAMTACCT: '0',
                            MAXAMTACCT: '0',
                            PAYTYPEACCT: '',
                            FEETYPEACCT: '',
                            FEECODE: '',
                            CARDEND: item.CARDNBR,
                            IFFLG: true
                        };
                        console.log("acctPlan", acctPlan);
                        this.acctPlanData.push(acctPlan);
                    }
                }

            });

            console.log("this.acctPlanData", this.acctPlanData);
        },

        updateacct(acctrow) {
            console.log("this.selectedList.length", this.selectedList.length);
            if (this.selectedList.length != this.speechList.length) {
                this.$alert('话术尚未全部勾选！', '提示', {
                    customClass: 'warning', type: 'warning',
                });
                return;
            }
            console.log("acctrow", acctrow);

            this.confimData.UPDTYPE = '0';
            this.confimData.PLAINNO = acctrow.CPNOACCT;
            this.confimData.NBRMTH = acctrow.NBRMTHACCT;
            this.confimData.MINMPAMT = acctrow.MINAMTACCT;
            this.confimData.MAXMPAMT = acctrow.MAXAMTACCT;
            this.confimData.MINAUTAMT = '';
            this.centerDialogVisibleclose1 = true;

        },
        updatecard(acctrow) {
            console.log("this.selectedList.length", this.selectedList.length);
            if (this.selectedList.length != this.speechList.length) {
                this.$alert('话术尚未全部勾选！', '提示', {
                    customClass: 'warning', type: 'warning',
                });
                return;
            }
            console.log("acctrow", acctrow);

            this.confimData.UPDTYPE = '1';
            this.confimData.CARDNO = acctrow.CARDEND;
            this.confimData.PLAINNO = acctrow.CPNO;
            this.confimData.NBRMTH = acctrow.NBRMTH;
            this.confimData.MINMPAMT = acctrow.MINAMT;
            this.confimData.MAXMPAMT = acctrow.MAXAMT;
            this.confimData.MINAUTAMT = acctrow.MINAUTAMT;
            this.centerDialogVisibleclose1 = true;

        },
        submitForm() {
            this.centerDialogVisibleclose1 = false;
            if (this.confimData.UPDTYPE === '0') {
                const appBody_4078 = {
                    CARDNBR: this.sizeForm.CARDNBR,
                    PINFLAG: 0,
                    SEVOPT: '16',
                    CHKOPT: '0000000000',
                    PURCHYN: '',
                    CPNO: this.confimData.PLAINNO, // 自动分期计划编号
                    NBRMTH: this.confimData.NBRMTH, // 自动分期期数
                    MINMPAMT: this.confimData.MINMPAMT, // 自动分期交易金额最小值
                    MAXMPAMT: this.confimData.MAXMPAMT, // 自动分期交易金额最大
                    RMBBILL: 0,
                };
                let tran4078Params = JSON.parse(JSON.stringify(this.defaultParams));
                tran4078Params.body.appHead.tranCode = '4078';
                tran4078Params.body.appBody = appBody_4078;

                this.$post.common.transPort(tran4078Params).then((res) => {
                    if (res.status === 200) {
                        const result = JSON.parse(res.data.jsonRes);
                        console.log(result, 111111);
                        if (result.sysHead.rspCd === '000000') {
                            this.$alert('修改成功', '提示', {
                                customClass: 'success', type: 'success',
                            });
                            this.onLoadAutoOBJ3();
                        } else {
                            const errorMsg = `错误代码：${result.sysHead.rspCd}, 错误信息：${result.sysHead.rspMsg}`;
                            this.$alert(errorMsg, '提示', {
                                customClass: 'error', type: 'error',
                            });
                        }
                    } else {
                        this.$alert('请求失败!', '提示', {
                            customClass: 'error', type: 'error',
                        });
                    }
                });
            } else {
                const appBody_4077 = {
                    CARDNBR: this.confimData.CARDNO,
                    PINFLAG: '0',
                    PIN: '',
                    SERCNT: '30000000000000000000',
                    CPNO: this.confimData.PLAINNO, // 自动分期计划编号
                    NBRMTH: this.confimData.NBRMTH, // 自动分期期数
                    MINMPAMT: this.confimData.MINMPAMT, // 自动分期交易金额最小值
                    MAXMPAMT: this.confimData.MAXMPAMT, // 自动分期交易金额最大
                    MINAUTAMT: this.confimData.MINAUTAMT,//自动分期下限金额
                };
                let tran4077Params = JSON.parse(JSON.stringify(this.defaultParams));
                tran4077Params.body.appHead.tranCode = '4077';
                tran4077Params.body.appBody = appBody_4077;

                this.$post.common.transPort(tran4077Params).then((res) => {
                    if (res.status === 200) {
                        const result = JSON.parse(res.data.jsonRes);
                        console.log(result, 111111);
                        if (result.sysHead.rspCd === '000000') {
                            this.$alert('修改成功', '提示', {
                                customClass: 'success', type: 'success',
                            });
                            this.onLoadAutoOBJ3();
                        } else {
                            const errorMsg = `错误代码：${result.sysHead.rspCd}, 错误信息：${result.sysHead.rspMsg}`;
                            this.$alert(errorMsg, '提示', {
                                customClass: 'error', type: 'error',
                            });
                        }
                    } else {
                        this.$alert('请求失败!', '提示', {
                            customClass: 'error', type: 'error',
                        });
                    }
                });
            }

        },


        NBRMTH2Change() {
            console.log(this.sizeForm.NBRMTH2, this.sizeForm.MINAMTACCT);
            if (this.sizeForm.NBRMTH2 == '003') {
                this.is3 = true;
                this.sizeForm.CPNO2 = '4001';
            } else {
                this.is3 = false;
            }
        },
        async get_4078(CPNO = '0000', NBRMTH = '00') {
            // 4078 配置请求头
            const appBody_4078 = {
                CARDNBR: this.sizeForm.CARDNBR,
                PINFLAG: 0,
                SEVOPT: '16',
                CHKOPT: '0000000000',
                PURCHYN: '',
                CPNO, // 自动分期计划编号
                NBRMTH, // 自动分期期数
                MINMPAMT: '', // 自动分期交易金额最小值
                MAXMPAMT: '', // 自动分期交易金额最大值
                RMBBILL: 0,
            };
            console.log(appBody_4078);
            const result_4078 = await get_3xxx(
                '4078',
                '自动分期设置',
                appBody_4078,
                this,
                false,
            );
            console.log(result_4078);
            if (!result_4078) return false;
            this.onLoadAutoOBJ();
            this.$alert('自动分期设置成功,请勿重复提交 !', '自动分期设置提示！', {
                confirmButtonText: '确定',
                center: true,
                showClose: false,
                customClass: 'success', type: 'success',
            });
        },
        async onColseAuto() {
            const confirmResult = await this.$confirm(
                '此操作将卡账单自动分期操作, 您确认要关闭自动分期吗？',
                '账单自动分期提示',
                {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning',
                },
            ).catch(err => err);
            if (confirmResult !== 'confirm') return this.$message.info('已取消关闭自动分期');

            this.get_4078();
            this.showTrial = !this.showTrial;
        },
        async onOpenAuto() {
            const confirmResult = await this.$confirm(
                '此操作将卡账单自动分期操作, 您确认要开通自动分期吗？',
                '账单自动分期提示',
                {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning',
                },
            ).catch(err => err);
            if (confirmResult !== 'confirm') return this.$message.info('已取消开通自动分期');

            this.get_4078(this.sizeForm.CPNO2, this.sizeForm.NBRMTH2);
            this.showEdit = !this.showEdit;
        },

        // 修改期数
        async fqxg(val) {
            const confirmResult = await this.$confirm(
                '确定修改分期参数吗？',
                '提示',
                {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning',
                },
            ).catch(err => err);
            if (confirmResult !== 'confirm') return this.$message.info('操作成功');

            const defaultParams = JSON.parse(JSON.stringify(this.defaultParams));
            defaultParams.body.appHead.tranCode = '4077';
            if (val == '1' || val == '3') {
                // 修改期数
                defaultParams.body.appHead.tranCode = '4077';
                const appBody_4077 = {
                    CARDNBR: this.sizeForm.CARDNBR,
                    PINFLAG: 0,
                    SERCNT: '3', // 修改参数
                    NBRMTH: val == '1' ? this.sizeForm.NBRMTH : this.sizeForm.NBRMTHACCT,
                    //MINAMT: sizeForm.MINAMT, 
                };
                defaultParams.body.appBody = appBody_4077;
            } else if (val == '2' || val == '4') {
                // 修改最小起分金额
                defaultParams.body.appHead.tranCode = '4078';
                const appBody_4078 = {
                    CARDNBR: this.sizeForm.CARDNBR,
                    PINFLAG: 0,
                    SEVOPT: '16',
                    CHKOPT: '0000000000',
                    //PURCHYN: '',
                    //CPNO, // 自动分期计划编号
                    //NBRMTH: sizeForm.NBRMTHACCT, // 自动分期期数
                    MINAMT: val == '2' ? this.sizeForm.MINAMT : this.sizeForm.NBRMTHACCT,
                    //MINMPAMT: '', // 自动分期交易金额最小值
                    //MAXMPAMT: '', // 自动分期交易金额最大值
                    //RMBBILL: 0,
                };
                defaultParams.body.appBody = appBody_4078;
            }

            this.$post.common.transPort(defaultParams).then(
                (res) => {
                    if (res.status === 200) {

                        const result = JSON.parse(res.data.jsonRes);
                        if (result.sysHead.rspCd == '000000') {
                            this.$alert('修改成功!', '提示', {
                                customClass: 'success', type: 'success',
                            });
                            this.onLoadAutoOBJ();
                        } else {
                            const errorMsg = `错误代码：${result.sysHead.rspCd}, 错误信息：${result.sysHead.rspMsg}`;
                            this.$alert(errorMsg, '提示', {
                                customClass: 'error', type: 'error',
                            });
                        }
                    } else {
                        this.$alert('请求失败！', '提示', {
                            customClass: 'error', type: 'error',
                        });
                    }
                });
        },

        handleClickbtn() {
            this.MenuId = getBusinessMenuId('/businessSystem/accountCardDetaileQuery', this.businessMenu);
            console.log('this.MenuId____', this.MenuId);
            this.$router.push({ name: 'accountCardDetaileQuery', path: '/businessSystem/accountCardDetaileQuery', params: { id: this.MenuId } });
        }
    },

}
</script>

<style  scoped lang="scss">
.automaticstagset-contnair {
    /deep/.el-card__header {
        padding: 8px !important;
    }
    .el-form {
        margin: 0 auto;
    }
    /deep/.form-row {
        width: 100%;
        margin: 0 auto;
        .el-form {
            //   text-align: left;

            width: 100%;
            margin: 0 auto;
            //   width: 500px;
            .el-form-item {
                text-align: center;
            }
        }
        .el-select {
            width: 90%;
            margin-bottom: 15px;
        }
    }
    .cell .payAcount {
        width: 80%;
        margin-right: 15px;
    }
    .el-form-item {
        text-align: left;
    }
}
</style>
